package com.coder.algorithm.offer_2;

import com.coder.algorithm.struct.BinaryTreeNode;

/**
 * 二叉树的深度
 *
 * @author yuhushuan
 * @date 2020/6/30 11:40
 */
public class _55_1_TreeDepth {
    private static int getTreeDepth(BinaryTreeNode root) {
        if (root == null) {
            return 0;
        }
        int left = getTreeDepth(root.left);
        int right = getTreeDepth(root.right);
        return Math.max(left, right) + 1;
    }

    public static void main(String[] args) {
        BinaryTreeNode root;

        // 功能测试
        // 普通二叉树
        root = BinaryTreeNode.getTestBinaryTree_1();
        print(root);
        // 只有左子树
        root = BinaryTreeNode.createOnlyLeftNodeTree(5);
        print(root);
        // 只有右子树
        root = BinaryTreeNode.createOnlyRightNodeTree(3);
        print(root);

        // 特殊输入测试
        print(new BinaryTreeNode(3));
        print(null);
    }

    private static void print(BinaryTreeNode root) {
        System.out.println("二叉树：");
        BinaryTreeNode.drawBinaryTree(root);
        System.out.println("最大深度为：" + getTreeDepth(root));
    }
}
